package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.acewill.yxd.yunxundian.BaseActivity;
import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.pubClass.SimpleSpinnerOption;

/**
 * Created by xxx on 2018/1/5.
 */

public class selectMailAdapter extends BaseAdapter{

    private List<SimpleSpinnerOption> list;
    private Context context;
    private int clickTemp=-10;

    public selectMailAdapter(Context context,List<SimpleSpinnerOption> list){
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void setSecletion(int position) {
        clickTemp = position;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.mulity_item_view,null);
            holder=new ViewHolder();
            holder.X_checkbox= (CheckBox) convertView.findViewById(R.id.X_checkbox);
            holder.X_item_text= (TextView) convertView.findViewById(R.id.X_item_text);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.X_item_text.setText(list.get(position).getName());
        if (list.get(position).isChecked()) {
            holder.X_checkbox.setChecked(true);
        }else {
            holder.X_checkbox.setChecked(false);
        }
        return convertView;
    }

    public List<SimpleSpinnerOption> getSelectList(){
        if (list!=null&&list.size()>0){
            List<SimpleSpinnerOption> selectList = new ArrayList<>();
            for (SimpleSpinnerOption option:list) {
                if (option.isChecked()){
                    selectList.add(option);
                }
            }
            return selectList;
        }
        return null;
    }
    public List<SimpleSpinnerOption> getAllList(){
        if (list!=null&&list.size()>0){
            return list;
        }
        return null;
    }
    public class ViewHolder{
        TextView X_item_text;
        CheckBox X_checkbox;
    }
}
